package com.penglecode.commons.util;

import org.springframework.util.Assert;

public class Pager {

	private int currentPage = 1;
	
	private int pageSize = 10;
	
	private int totalRowCount = 0;
	
	private int totalPageCount = 0;

	public Pager() {
		super();
	}

	public Pager(int currentPage, int pageSize) {
		super();
		setCurrentPage(currentPage);
		setPageSize(pageSize);
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		Assert.state(currentPage > 0, "'currentPage' must be > 0!");
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		Assert.state(pageSize > 0, "'pageSize' must be > 0!");
		this.pageSize = pageSize;
	}

	public int getTotalRowCount() {
		return totalRowCount;
	}

	public void setTotalRowCount(int totalRowCount) {
		this.totalRowCount = totalRowCount;
		if(this.totalRowCount > 0){
			this.totalPageCount = this.totalRowCount % this.pageSize == 0 ? (this.totalRowCount / this.pageSize) : ((this.totalRowCount / this.pageSize) + 1);
		}else{
			this.totalPageCount = 0;
		}
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public String toString() {
		return "Pager [currentPage=" + currentPage + ", pageSize=" + pageSize
				+ ", totalRowCount=" + totalRowCount + ", totalPageCount="
				+ totalPageCount + "]";
	}

}
